from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-30 14:08:20.961141
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 30, Apr, 2021
Time: 14:08:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8740
Nobs: 277.000 HQIC: -48.5791
Log likelihood: 3346.22 FPE: 4.98108e-22
AIC: -49.0515 Det(Omega_mle): 3.61996e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.422687 0.120328 3.513 0.000
L1.Burgenland 0.074059 0.059884 1.237 0.216
L1.Kärnten -0.224820 0.053077 -4.236 0.000
L1.Niederösterreich 0.086678 0.129318 0.670 0.503
L1.Oberösterreich 0.228939 0.124372 1.841 0.066
L1.Salzburg 0.267611 0.068684 3.896 0.000
L1.Steiermark 0.111119 0.087289 1.273 0.203
L1.Tirol 0.122709 0.060376 2.032 0.042
L1.Vorarlberg -0.036493 0.055398 -0.659 0.510
L1.Wien -0.043236 0.111855 -0.387 0.699
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.443963 0.139348 3.186 0.001
L1.Burgenland 0.005960 0.069349 0.086 0.932
L1.Kärnten 0.329415 0.061467 5.359 0.000
L1.Niederösterreich 0.105017 0.149759 0.701 0.483
L1.Oberösterreich -0.064477 0.144032 -0.448 0.654
L1.Salzburg 0.219589 0.079541 2.761 0.006
L1.Steiermark 0.093177 0.101087 0.922 0.357
L1.Tirol 0.136481 0.069919 1.952 0.051
L1.Vorarlberg 0.151341 0.064154 2.359 0.018
L1.Wien -0.410705 0.129537 -3.171 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.270237 0.061099 4.423 0.000
L1.Burgenland 0.103822 0.030407 3.414 0.001
L1.Kärnten -0.014237 0.026951 -0.528 0.597
L1.Niederösterreich 0.080919 0.065664 1.232 0.218
L1.Oberösterreich 0.285667 0.063153 4.523 0.000
L1.Salzburg 0.015769 0.034876 0.452 0.651
L1.Steiermark 0.000573 0.044323 0.013 0.990
L1.Tirol 0.070101 0.030657 2.287 0.022
L1.Vorarlberg 0.074695 0.028129 2.655 0.008
L1.Wien 0.115031 0.056797 2.025 0.043
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.212122 0.058360 3.635 0.000
L1.Burgenland 0.027918 0.029044 0.961 0.336
L1.Kärnten 0.010318 0.025742 0.401 0.689
L1.Niederösterreich 0.053280 0.062720 0.849 0.396
L1.Oberösterreich 0.397859 0.060321 6.596 0.000
L1.Salzburg 0.078219 0.033312 2.348 0.019
L1.Steiermark 0.130209 0.042335 3.076 0.002
L1.Tirol 0.050450 0.029282 1.723 0.085
L1.Vorarlberg 0.080967 0.026868 3.014 0.003
L1.Wien -0.041847 0.054250 -0.771 0.440
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.478853 0.114320 4.189 0.000
L1.Burgenland 0.098983 0.056894 1.740 0.082
L1.Kärnten 0.008852 0.050427 0.176 0.861
L1.Niederösterreich 0.008118 0.122861 0.066 0.947
L1.Oberösterreich 0.124785 0.118163 1.056 0.291
L1.Salzburg 0.054146 0.065254 0.830 0.407
L1.Steiermark 0.066343 0.082931 0.800 0.424
L1.Tirol 0.205390 0.057361 3.581 0.000
L1.Vorarlberg 0.034138 0.052632 0.649 0.517
L1.Wien -0.072824 0.106271 -0.685 0.493
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214142 0.090363 2.370 0.018
L1.Burgenland -0.011473 0.044971 -0.255 0.799
L1.Kärnten -0.006638 0.039859 -0.167 0.868
L1.Niederösterreich -0.017225 0.097114 -0.177 0.859
L1.Oberösterreich 0.418521 0.093401 4.481 0.000
L1.Salzburg 0.012762 0.051580 0.247 0.805
L1.Steiermark -0.028183 0.065552 -0.430 0.667
L1.Tirol 0.163597 0.045341 3.608 0.000
L1.Vorarlberg 0.056991 0.041602 1.370 0.171
L1.Wien 0.203437 0.084001 2.422 0.015
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218669 0.109635 1.995 0.046
L1.Burgenland 0.021301 0.054562 0.390 0.696
L1.Kärnten -0.071163 0.048360 -1.472 0.141
L1.Niederösterreich -0.063010 0.117826 -0.535 0.593
L1.Oberösterreich 0.021442 0.113320 0.189 0.850
L1.Salzburg 0.081309 0.062580 1.299 0.194
L1.Steiermark 0.324694 0.079532 4.083 0.000
L1.Tirol 0.460844 0.055010 8.377 0.000
L1.Vorarlberg 0.145653 0.050475 2.886 0.004
L1.Wien -0.136710 0.101916 -1.341 0.180
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208692 0.131015 1.593 0.111
L1.Burgenland 0.040833 0.065202 0.626 0.531
L1.Kärnten -0.075365 0.057791 -1.304 0.192
L1.Niederösterreich 0.111361 0.140803 0.791 0.429
L1.Oberösterreich 0.014437 0.135419 0.107 0.915
L1.Salzburg 0.195127 0.074784 2.609 0.009
L1.Steiermark 0.129875 0.095041 1.367 0.172
L1.Tirol 0.055999 0.065738 0.852 0.394
L1.Vorarlberg 0.106421 0.060318 1.764 0.078
L1.Wien 0.220780 0.121790 1.813 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.537641 0.072359 7.430 0.000
L1.Burgenland -0.013762 0.036011 -0.382 0.702
L1.Kärnten -0.015223 0.031918 -0.477 0.633
L1.Niederösterreich 0.095328 0.077765 1.226 0.220
L1.Oberösterreich 0.304882 0.074792 4.076 0.000
L1.Salzburg 0.014594 0.041303 0.353 0.724
L1.Steiermark -0.044162 0.052491 -0.841 0.400
L1.Tirol 0.082784 0.036307 2.280 0.023
L1.Vorarlberg 0.101708 0.033313 3.053 0.002
L1.Wien -0.059712 0.067265 -0.888 0.375
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.159921 0.089790 0.165273 0.217770 0.077609 0.084717 0.001979 0.160081
Kärnten 0.159921 1.000000 0.054684 0.208645 0.185812 -0.066365 0.176063 0.021071 0.302904
Niederösterreich 0.089790 0.054684 1.000000 0.244660 0.087964 0.317641 0.146785 0.021622 0.311984
Oberösterreich 0.165273 0.208645 0.244660 1.000000 0.303364 0.260248 0.096063 0.060546 0.141027
Salzburg 0.217770 0.185812 0.087964 0.303364 1.000000 0.148487 0.063696 0.088934 0.015516
Steiermark 0.077609 -0.066365 0.317641 0.260248 0.148487 1.000000 0.095787 0.099698 -0.100014
Tirol 0.084717 0.176063 0.146785 0.096063 0.063696 0.095787 1.000000 0.152841 0.153265
Vorarlberg 0.001979 0.021071 0.021622 0.060546 0.088934 0.099698 0.152841 1.000000 -0.008574
Wien 0.160081 0.302904 0.311984 0.141027 0.015516 -0.100014 0.153265 -0.008574 1.000000